<script setup lang="ts">
  import { onLaunch, onShow, onHide, onLoad } from '@dcloudio/uni-app';
  import { useAppStoreWithOut } from './store/modules/app';
  import { CacheEnum } from './enums/cacheEnum';

  const {
    miniProgramConfig,
    getAccountInfoSync,
    setResolvePrivacyAuthorization,
    setPrivacyPopupVisible,
  } = useAppStoreWithOut();

  getAccountInfoSync();
  /** 每次启动程序 清空文件缓存 */
  function removeSavedFile() {
    let fileSystemManager = wx.getFileSystemManager();
    fileSystemManager.readdir({
      dirPath: `${wx.env.USER_DATA_PATH}`,
      success: ({ files }) => {
        files.forEach((item) => {
          fileSystemManager.unlink({
            filePath: `${wx.env.USER_DATA_PATH}/${item}`,
          });
        });
      },
    });
  }

  onLaunch(async () => {
    console.log('App Launch');
    uni.removeStorageSync(CacheEnum.localareaData);
    // #ifndef H5
    await miniProgramConfig();
    // #endif
    // #ifdef MP-WEIXIN
    removeSavedFile();
    // #endif
  });
  onShow(() => {
    if (wx.onNeedPrivacyAuthorization) {
      console.log('onNeedPrivacyAuthorization init');
      wx.onNeedPrivacyAuthorization((resolve) => {
        setResolvePrivacyAuthorization(resolve);
        setPrivacyPopupVisible(true);
        console.log('onNeedPrivacyAuthorization success');
      });
    }
    console.log('App Show');
  });
  onLoad(() => {
    console.log('App Load');
  });
  onHide(() => {
    console.log('App Hide');
  });
</script>

<style lang="scss">
  @import './static/css/iconfont.css';
  @import './static/css/ant-iconfont.css';
  @import './components/uParse/src/wxParse.css';
  @import './styles/styles.scss';
</style>
